/**
 * \* Created with IntelliJ IDEA.
 * \* User: 冯若航
 * \* Date: 2021/7/2
 * \* Time: 17:50
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class 连续子数组的最大和 {
    public int maxSubArray(int[] nums) {
        int n=nums.length;
        if(n==0){
            return 0;
        }
        //base case
        int dp_0=nums[0];
        int dp_1=0;
        int res=dp_0;
        for(int i=1;i<n;i++){
            dp_1=Math.max(nums[i],nums[i]+dp_0);
            dp_0=dp_1;
            //update result
            res=Math.max(res,dp_1);
        }
        return res;
    }
}